/**
 * 直接注入标签页的脚本
 */

import { onMessage } from '@shared/clientMessage'
import { PostMessageType } from '@shared/types'

import { createApp } from 'vue'
import App from './App.vue'

const sheet = new CSSStyleSheet()

document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet]

onMessage(PostMessageType.DATA, (data: string) => {
  try {
    sheet.replaceSync(data)
  } catch (error) {
    console.error(error)
  }
})

const container = document.createElement('div')
document.body.append(container)

const app = createApp(App)
app.mount(container)
